import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    redirect: '/index',
    component: () => import('@/views/Home/Home.vue'),
    children: [
      {
        path: '/index',
        name: 'index',
        component: () => import('@/views/IndexPage/IndexPage.vue'),
        meta: {
          isIndex: true
        }
      },
      {
        path: '/case',
        name: 'case',
        component: () => import('@/views/Case/Case.vue'),
        meta: {
          active: 'case'
        }
      },
      {
        path: '/news',
        name: 'news',
        component: () => import('@/views/news/News.vue'),
        meta: {
          active: 'news'
        }
      },
      {
        path: '/details/:id',
        name: 'details',
        component: () => import('@/views/news/NewsDetails.vue'),
        meta: {
          active: 'news'
        }
      },
      {
        path: '/about',
        name: 'about',
        component: () => import('@/views/About/About.vue'),
        meta: {
          active: 'about'
        }
      },
      {
        path: '/application',
        name: 'application',
        component: () => import('@/views/Application/Application.vue'),
      }
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // 动态设置导航栏active样式
  if (to.meta.isIndex !== 'undefined' && to.meta.isIndex === true) {
    Vue.prototype.$EventBus.$emit('IndexStatus', to.meta.isIndex)
  }else{
    Vue.prototype.$EventBus.$emit('IndexStatus')
  }
  next()
})

export default router
